// pages/showGoods/showGoods.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    sentence:"为您找到以下数据",
    pageNum:1,
    size:4,
    sum:'',
    keyValue:'',
    ishidden:false,
    isLoading:false
  },
  
 getInfo(){
   this.setData({
     isLoading:true
   })
  wx.request({
    url: 'http://124.222.95.170:21311/goods/page',
    header: {
      'Cookie': wx.getStorageSync('sessionid')
    },
    data:{
     "name":this.data.keyValue,
     "page":this.data.pageNum,
     "pageSize":this.data.size
    },
    success:(res)=>{
      console.log(res.data)
      if(res.data.data.records.length ==0){
        this.setData({
          sentence:"很抱歉，未找到相关书籍（＞人＜；）",
          keyValue:'',
          ishidden:true
        })
        this.getInfo()
      }else{
        this.setData({
          sum :res.data.data.total,
          list:[...this.data.list,...res.data.data.records]
        })
      }
      
    },
    complete:()=>{
      this.setData({
        isLoading:false
      })
    }
  })
 },

  onLoad: function (options) {
   this.setData({
    keyValue: options.name
   })
   this.getInfo()
  },

  onReachBottom: function () {
    if(this.data.pageNum * this.data.size >= this.data.sum){
      wx.showToast({
        title: '已经到底啦~',
        icon:'none'
      })
      return
    }
    if(this.data.isLoading) return
    this.setData({
    pageNum:this.data.pageNum + 1
    })
    this.getInfo()
  }
})